#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    int jump(vector<int>& nums) {
        int n = nums.size(); 
        if(n < 2) return 0;
        int cover=nums[0]; int newcover=nums[0];
        int ans = 0;
        for(int i=0; i<=cover; ++i){
            if(newcover < i+nums[i]) newcover = i+nums[i];
            if(i==cover){
                cover = newcover;
                ++ans;
            }
            if(cover>=n-1) return ++ans;
        }
        return ans;
    }
};